const enterpriseVue = new Vue({
    el: '#app',
    data() {
      return {
        pickerOptions: pickerOptions,
        rules: {
          Brand_Name: [{
            required: true, 
            message: '请输入品牌名称',
            trigger: 'blur',
          }]
        },
        fileList2: [{ name: 'food.jpeg', url: '../../../../admin/images/act.jpg' }],
        dialogImageUrl: '',
        dialogVisible: false,
        form: {
          Other_Service_Type_SerialNumber:'',
          Other_Service_Type_Name:'',
          Picture_URL:'',
          Other_Service_Explain:''
        },
        pic:'',
        loading: false
      } 
    },
    mounted() {
      this.uploadFront()
    },
    methods: {
      submitForm(formName) {
        let _this = this
        this.$refs[formName].validate((valid) => {
          if (valid) {
            _this.loading = true
            $.ajax({
              url: DomainName + `/getAddAction?token=${$.cookie('token')}`,
              type: 'POST',
              data: {
                Data: JSON.stringify({
                  other_service_type: [_this.form]
                }),
              },
              success: function (res) {
                console.log('提交结果', res)
                _this.$message.success("提交成功")
                window.history.go(-1);
              },
              error: function () {
                _this.$message.error("操作失败，请稍后再试")
              },
              complete: function (XMLHttpRequest) {
                _this.loading = false
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              }
            });
          } else {
            console.log("error submit!!");
            return false;
          }
  
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
       //商品封面图片
    uploadFront(file) {
      console.log('上传第一张图片')
      let _this = this
      let num = 1
      new Compressor(file, {
        quality: num,
        success(file) {
          console.log(file.size)
          const formData = new FormData();
          formData.append('file', file, file.name);
          let oFileReader = new FileReader();
          oFileReader.readAsDataURL(file);
          oFileReader.onload = function (e) {
            $.ajax({
              type: 'POST',
              url: DomainName + '/FileList',
              data: {
                Data: e.target.result,
                DataLength: file.size,
                FileName: file.name
              },
              complete: function (XMLHttpRequest) {
                _this.loading = false
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              },
              success: function (Result) {
                _this.pic = e.target.result
                if (Result.Status == "success") {
                  _this.form.Picture_URL = Result.Picture_Url
                  _this.$message.success('上传成功')
                  console.log(Result.Picture_Url);
                } else {
                  _this.$message.error('上传失败')
                }
              },
              error: function () {
                _this.$message.error("操作失败，请稍后再试")
              },
              dataType: "json"
            });
          }
        },
        error(err) {
          console.log(err.message);
        },
      });
    },
    }
  })